
/**
* Edit CSS from the web browser
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*@package css_edit
*/
(function($){

var 
	saveCss = function($me){
		var def={};
		$me.find(">div:gt(0)").each( function(){
				var	l = $(this).find(">span.css_l").html(),
					r = $(this).find(">span.css_r").html();
				if ( l && r )
					def[l] = r;
			});
		$me.find(">input[type=hidden]:eq(0)").val( $.param( def ) );
	},

	createRow = function(e){
		var	src = e.data.find(">div:hidden"),
			new_row = src.clone(true);
		src.after( new_row );
		new_row.fadeIn("fast");
	};

Core.ObjectTypes["fieldset.css_edit"] = function(){

	var $this = $(this);

	$this.find(">span.ui-icon").bind("click", $this, createRow );

	$this.find(">div").each( function(){
			$(this).find(">span.ui-icon").bind("click", $this, function(e){
					$(this).parent().fadeOut("fast", function(){
							$(this).remove();
							saveCss(e.data);
						});
				});
			$(this).find(">span.css_l,>span.css_r").bind("click",$this, function(e){
					var x=prompt( "CSS Element:", $(this).html() )
					if(x) $(this).html(x)
					saveCss(e.data)
					return false;
				});
		});

	saveCss($this);
};

}) (jQuery);
